<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>淘宝搜索</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            height: 2000px;
        }

        div:nth-of-type(1) {
            height: 200px;
            background-color: aqua;
        }

        div:nth-of-type(2) {
            height: 200px;
            background-color: brown;
        }

        div:nth-of-type(3) {
            height: 100px;
            background-color: rgb(214, 145, 145);
            width: 100%;
            text-align: center;
        }

        div:nth-of-type(4) {
            height: 400px;
            background-color: rgb(75, 42, 165);
        }

        input:nth-of-type(1) {
            width: 500px;
            height: 50px;
            border-radius: 50px 0px 0px 50px;
            float: left;
            border-right: none;
            box-sizing: border-box;
            margin-top: 27px;
        }

        input:nth-of-type(2) {
            width: 50px;
            height: 50px;
            text-align: center;
            float: left;
            border-left: none;
            background-color: gray;
            color: white;
            box-sizing: border-box;
            margin-top: 27px;
            cursor: pointer;
        }

        form {
            overflow: hidden;
            height: 100px;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div></div>
    <div></div>
    <div id="nav">
        <form action="">
            <input type="text">
            <input type="text" value="搜索">
        </form>
    </div>
    <div></div>
</body>
    <script>
        let nav = document.getElementById('nav');
        window.onscroll = function () {

            if (window.scrollY >= 400) {
                nav.style.position = 'fixed'
                nav.style.top = 0;
            } else {
                nav.style.position = '';
            }
        }
    </script>
</html>